package com.zrrd.gmall.product.controller;

import com.zrrd.gmall.common.result.Result;
import com.zrrd.gmall.model.product.BaseAttrInfo;
import com.zrrd.gmall.model.product.BaseAttrValue;
import com.zrrd.gmall.product.service.BaseAttrService;
import io.swagger.annotations.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class BaseAttrController {

    @Autowired
    private BaseAttrService baseAttrService;

    //根据分类ID获取平台属性以及属性值
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> attrInfoList(@PathVariable("category1Id") Long category1Id,
                                                   @PathVariable("category2Id") Long category2Id,
                                                   @PathVariable("category3Id") Long category3Id) {
        List<BaseAttrInfo> attrInfoList = baseAttrService.getAttrInfoList(category1Id, category2Id, category3Id);
        return Result.ok(attrInfoList);
    }

    //添加 修改平台属性
    @PostMapping("/saveAttrInfo")
    public Result<String> saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        baseAttrService.saveAttrInfo(baseAttrInfo);
        return Result.ok("成功");
    }

    //根据平台属性id获取属性对象
    @GetMapping("/getAttrValueList/{attrId}")
    public Result<List<BaseAttrValue>> getAttrValueList(@PathVariable("attrId") Long attrId){
        List<BaseAttrValue> attrValues = baseAttrService.getAttrInfo(attrId);
        return Result.ok(attrValues);
    }
}
